package com.shangcheng.server.controller;

import com.shangcheng.autoconfig.template.OssTemplate;
import com.shangcheng.model.vo.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;

@RestController
@RequestMapping("/aliyun/oss")
public class OssController {
    @Autowired
    private OssTemplate ossTemplate;

    @PostMapping("upload")
    public ResponseEntity upload(MultipartFile photoFile){
        String url="";
        try {
             url = ossTemplate.upload(photoFile.getOriginalFilename(), photoFile.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        HashMap<String, String> map = new HashMap<>();
        map.put("url",url);
        return ResponseEntity.ok(new Result(200,map,""));
    }
}
